export const mutations = {
  count (state, count) {
    state.count = count
  },
  sideNav (state, nav) {
    state.sideNav = nav
  },
  addRole (state, roleInfo) {
    state.roleInfo = roleInfo
  },

  // 刷新页面时从localstorage中取值，并重置activeTabsList
  resetActiveTabsList (state, activeTabsList) {
    state.activeTabsList = activeTabsList
  },
  // 路由跳转时将路由添加到激活页面列表中，需要判断是否存在
  setActiveTabs (state, activeTabs) {
    let flag = true
    let list = JSON.parse(JSON.stringify(state.activeTabsList))
    let len = list.length

    if (len > 0) {
      // state.activeTabsList.map((item) => {
      for (let i = 0; i < len; i++) {
        let item = list[i]
        if (item.route_url === activeTabs.route_url) flag = false
        // 子系统次级页面触发tab功能完善
        if (activeTabs.type === 'micro') {
          let url = activeTabs.route_url
          url = url.split('?')[0]
          if (item && item.route_url.includes(url)) {
            list[i] = {
              menu_name: activeTabs.menu_name,
              route_url: activeTabs.route_url,
              type: 'micro'
            }
            flag = false
          }
        }
      }
    }
    if (flag) {
      list.push(activeTabs)
    }
    state.activeTabsList = list
    window.localStorage.setItem('platFormActiveTabsList', JSON.stringify(list))
  },
  // 将需要删除的页面从列表中移除
  removeActiveTabs (state, tabIndex) {
    // let index = -1
    // state.activeTabsList.map((item, i) => {
    //   if (item.route_url === activeTabs.route_url) index = i
    // })
    if (tabIndex >= 0) state.activeTabsList.splice(tabIndex, 1)
    window.localStorage.setItem(
      'platFormActiveTabsList',
      JSON.stringify(state.activeTabsList)
    )
  },
  // 当前页面所在路由
  setActiveTab (state, activeTab) {
    state.activeTab = activeTab.substr(1)
    // console.log(activeTab.substr(1), 'vuex')
    window.localStorage.setItem('platFormActiveTab', state.activeTab)
  },
  setMenuTree (state, menuTree) {
    state.menuTree = menuTree
  },
  setDecomTree (state, decomTree) {
    state.decomTree = decomTree
  },
  setUserInfo (state, userInfo) {
    state.userInfo = userInfo
  },
  setOrgainzationTree (state, orgainzationTree) {
    state.orgainzationTree = orgainzationTree
  },
  // 设置左侧菜单是否折叠
  setLeftNavCollapse (state, isCollapse) {
    state.isLeftNavCollapse = isCollapse
  },
  // 设置左侧菜单是否隐藏
  setLeftNavHidden (state, isHidden) {
    state.isLeftNavHidden = isHidden
  },
  // 获取当前页面大小
  getPageSize (state, pageSize) {
    state.pageSize = pageSize
  },
  // 存储用户权限列表
  setUserAuth (state, userAuth) {
    state.userAuth = userAuth
    window.localStorage.setItem('industryUserAuth', JSON.stringify(userAuth))
    window.sessionStorage.setItem('industryUserAuth', JSON.stringify(userAuth))
  },
  // 获取当前页面权限
  getPageAuth (state, pageAuth) {
    state.pageAuth = pageAuth
  },
  //存储添加层号的计数
  SetNodeCount (state, nodeCount) {
    state.nodeCount = nodeCount
  },
  //项目设计与分解-左边树-编辑设计信息-确定的次数
  setEditDesignInfoCount (state, editDesignInfoCount) {
    state.editDesignInfoCount = editDesignInfoCount
  },
  // 获取主内容区滚动距离
  getScrollTop (state, scrollTop) {
    state.scrollTop = scrollTop
  },
  // 存储项目列表弹框中选中的项目id列表
  setProjectIdList (state, idList) {
    window.localStorage.setItem('projectIdList', JSON.stringify(idList))
    state.projectIdList = idList
  },
  // 存储切换单位的主键值
  setSwitchCompId (state, idList) {
    state.switchCompId = idList
  },
  //平台入驻流程v1.7.0-单位列表页面的单位是否有新增
  setHasTheUnitIncreaStatus (state, idList) {
    state.hasTheUnitIncreaStatus = idList;
  },
  // 设置权限树
  setPermissionTree (state, permissionTree) {
    state.permissionTree = permissionTree
  },
  // 存储项目信息
  setProjectInfo (state, projectInfo) {
    state.projectInfo = projectInfo
  },
  //智慧工地接入情况的详情
  setZHGDConSiInfo (state, zhgdConSituatDetailObj) {
    window.localStorage.setItem('zhgdConSituatDetailObj', JSON.stringify(zhgdConSituatDetailObj))
    state.zhgdConSituatDetailObj = zhgdConSituatDetailObj
  },
  // 存储选中的项目信息
  setProject (state, project) {
    window.localStorage.setItem('choosedProject', JSON.stringify(project))
    state.choosedProject = project
  },
  //建立组织
  setBuildOrg (state, buildOrg) {
    window.localStorage.setItem('getBuildOrg', JSON.stringify(buildOrg))
    state.getBuildOrg = buildOrg
  },
  //加入组织
  setJoinOrg (state, joinOrg) {
    window.localStorage.setItem('getJoinOrg', JSON.stringify(joinOrg))
    state.getJoinOrg = joinOrg
  },
  //切换组织或岗位 changeOrgOrStation
  setOrgOrgStation (state, changeOrgOrStation) {
    window.localStorage.setItem('getJoinOrg', JSON.stringify(changeOrgOrStation))
    state.changeOrgOrStation = changeOrgOrStation
  },
  // 存储选中的项目列表详细
  setProjectList (state, projectList) {
    window.localStorage.setItem('choosedProjectList', JSON.stringify(projectList))
    state.choosedProjectList = {
      list: projectList
    }
  },
  // 切换完善用户信息弹框是否可见
  toggleUserInfoDialogVisible (state, visible) {
    state.userInfoDialogVisible = visible
  },
  // 存储选中的经纬度
  setChoosedLat (state, latlnt) {
    state.choosedLat = latlnt
  },
  // 设置选择经纬度弹框是否可见
  setChooseLatVisible (state, visible) {
    state.chooseLatDialogVisible = visible
  },
  // 设置项目文档树
  setProjectFileTree (state, fileTree) {
    state.projectFileTree = fileTree
    window.localStorage.setItem('projectFileTree', JSON.stringify(fileTree))
  },
  // 设置用户菜单
  setUserMenu (state, userMenu) {
    state.userMenu = userMenu
    window.localStorage.setItem('platUserMenu', JSON.stringify(userMenu))
  },
  // 设置是否显示顶部菜单
  setShowTop (state, showTop) {
    state.showTop = showTop
  },
  // 设置是否显示左侧菜单
  setShowLeft (state, showLeft) {
    state.showLeft = showLeft
  }
}
